/* 
 *  Copyright (c) 2011—2013 Panguso.com. All rights reserved. 
 *  File Name:  GenaralLogOperation.java                                      
 *  File Contents Outline :   通常日志操作                 
 *  File  Create Date:   2012年7月30日
 *  File Version#: Revision#: #1                  
 *  File  Latest Modify Date : 2013年1月16日
 *  File Author :  bachuan@panguso.com
 */
package cn.edu.thu.log.util;

import java.util.ArrayList;
import java.util.List;
import org.deckfour.xes.classification.XEventAttributeClassifier;
import org.deckfour.xes.extension.XExtension;
import org.deckfour.xes.extension.std.XConceptExtension;
import org.deckfour.xes.extension.std.XTimeExtension;
import org.deckfour.xes.factory.XFactory;
import org.deckfour.xes.factory.XFactoryRegistry;
import org.deckfour.xes.info.XLogInfo;
import org.deckfour.xes.info.XLogInfoFactory;
import org.deckfour.xes.model.XAttribute;
import org.deckfour.xes.model.XLog;
import storage.dbhelper.LogHeadHelper;
import storage.dbobject.DbLogHead;

public class GenaralLogOperation {
	public static void setupBasicAttributes(XLog log) {
		setupClassifier(log);
		setupGlobalAttributes(log);
		setupExtensions(log);
	}
	/**
	 * set up classifier for log
	 */
	 private static  void setupClassifier(XLog log) {
		String[] keys = { XConceptExtension.KEY_NAME };
		XEventAttributeClassifier classifier;
		classifier = new XEventAttributeClassifier("activity classifier", keys);
		log.getClassifiers().add(classifier);

	}

	// set up extensions for log
	 private static void setupExtensions(XLog log) {
		XExtension timeExtension = XTimeExtension.instance();
		XExtension conceptExtension = XConceptExtension.instance();
		log.getExtensions().add(timeExtension);
		log.getExtensions().add(conceptExtension);

	}

	// set up global attributes
	 private static void setupGlobalAttributes(XLog log) {
		XFactory factory = XFactoryRegistry.instance().currentDefault();
		XAttribute attributeConcept = factory.createAttributeLiteral(
				XConceptExtension.KEY_NAME, "name", null);
		log.getGlobalEventAttributes().add(attributeConcept);
		XAttribute attributeTime = factory.createAttributeLiteral(
				XTimeExtension.KEY_TIMESTAMP, "time", null);
		log.getGlobalEventAttributes().add(attributeTime);

		log.getGlobalTraceAttributes().add(attributeConcept);
	}
		public static void writeLogToXES(XLog log,String xesName) {
			
		}
                /**
 * get teh location of content in logHead
 * @param tagLocation the location of the tag in tagList
 * @return the location of content in contentList in logHead
 */
    public static int getLogHeadLoc(int tagLocation,ArrayList<String> logHeadTagList) {
        LogHeadHelper logHeadH = new LogHeadHelper();
        List<DbLogHead> logHeadTags = logHeadH.getLogHeads(DbLogHead.cl_name, logHeadTagList.get(tagLocation));
        DbLogHead logHeadTag = logHeadTags.get(0);
        String locString = logHeadTag.getLocation();

        int loc = Integer.parseInt(locString) - 1;
        return loc;
    }
        public static int getLogEventSize(XLog logL) {
		int events = 0;
		XLogInfo info = null;
		info = XLogInfoFactory.createLogInfo(logL);
		events += info.getNumberOfEvents();
		return events;
	}
}
